﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System.Reflection;
using System.IO;
using System.IO.Ports;
using SerialPortHelperLib;
using System.Configuration;

namespace XChipTool
{
    public partial class XChip_ParameterExportOptions : DevExpress.XtraEditors.XtraForm
    {


        private SerialPort sPortTemp;
        public XChip_ParameterExportOptions()
        {
            InitializeComponent();
        }
        public XChip_ParameterExportOptions(SerialPort _sPortTemp)
        {
               sPortTemp = _sPortTemp;
               InitializeComponent();
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //parChecked  获取勾选项

            /*
            参数导出选项：
                        AE -->AE_cfg()
                        AF -->AF_cfg()
                        LENC -->Lenc_cfg()
                        HDR -->HDR_cfg()
                        NR3D -->NR3D_cfg()
                        SNR/YNR/YDE+ -->SNR_cfg() +YNR_cfg() +YDE_cfg()
                        AWB/CMX/CADJ -->AWB_cfg() +CMX_cfg() +CADJ_cfg()
                        Gamma -->Raw_gamma_cfg() +Rgb_gamma_cfg() +Yuv_gamma_cfg()
                        IQ_switch -->IQ_switch_cfg()
                        mjpeg  --> Mjpeg_cfg()
                        other -->BLC_cfg() +CIP_cfg() +isp_osd_sde_cfg() +IQ_oneself_cfg()

                        全部调用完成  调用 Top_enable_cfg()
            */
            //00-AE          01-AF        02-BLC        03-LENC            04-AWB        05-HDR        06-RAW_Gamma        07-RGB_Gamma
            //08-YUV_Gamma   09-CMX       10-NR3D       11-SNR             11-YNR        13-CIP        14-YDE              15-CADJ
            //16-IQ_Oneself  17-ISP_OSD   18-IQ_switch  19-car_back_line   20-Mjpeg      21-Top_enable
            List<string> SumMainList = new List<string>();
            string PathName = "";
            var chkIndexCollection = this.parChecked.CheckedItems.Cast<CheckedListBoxItem>()
    .OrderBy(item => item.Value);//获得所有选中行的集合
            var path = Application.StartupPath + "\\" + "CtoCodeLib.dll";
            if (!File.Exists(path))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show($"未找到到相应的CtoCodeLib.DLL！请联系管理员！");
                return;
            }
            ParameterConfig pcModel = new ParameterConfig();
            pcModel.Initialization(sPortTemp);
            Assembly assembly = Assembly.LoadFile(path);
            var objCreate = assembly.CreateInstance("XChipTool.CtoCode");
            foreach (CheckedListBoxItem item in chkIndexCollection)
            {
                if (item.Description.Contains("AE"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("AE_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无AE_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        pcModel.Hdr_mode,
                        pcModel.Sensor_i2c_id,
                        pcModel.Sensor_i2c_mode,
                        pcModel.Type_gain,
                        pcModel.Type_exp,
                        pcModel.Gain_shift,
                        pcModel.Exp_shift,
                        pcModel.Sensor_gain_addr,
 
                        pcModel.Sensor_gain_mask,
 
                        pcModel.Sensor_exp_addr,
   
                        pcModel.Sensor_exp_mask
                        
                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//AE");
                    PathName += "AE_";
                    SumMainList.AddRange(mainList);
                }
                if (item.Description.Contains("AF"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("AF_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无AF_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//AF");
                    PathName += "AF_";
                    SumMainList.AddRange(mainList);
                }
                if (item.Description.Contains("BLC"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("BLC_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无BLC_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        pcModel.Hdr_mode
                    });

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "BLC_";
                    SumMainList.Add("//BLC");
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("LENC"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("Lenc_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无Lenc_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        pcModel.Hdr_mode
                    });

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//LENC");
                    PathName += "LENC_";
                    SumMainList.AddRange(mainList);
                }
                if (item.Description.Contains("AWB"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("AWB_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无AWB_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        pcModel.Hdr_mode
                    });

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "AWB_";
                    SumMainList.Add("//AWB");
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("HDR"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("HDR_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无HDR_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        pcModel.Hdr_mode
                    });

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//HDR");
                    PathName += "HDR_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("Gamma"))
                {
                    // Gamma -->Raw_gamma_cfg() +Rgb_gamma_cfg() +Yuv_gamma_cfg()

                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("Raw_gamma_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无Raw_gamma_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);


                    method = objCreate.GetType().GetMethod("Rgb_gamma_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无Rgb_gamma_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);


                    method = objCreate.GetType().GetMethod("Yuv_gamma_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无Yuv_gamma_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//Gamma");
                    PathName += "Gamma_";
                    SumMainList.AddRange(mainList);
                    //处理代码
                }

                if (item.Description.Contains("CMX"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("CMX_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无CMX_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "CMX_";
                    SumMainList.Add("//CMX");
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("NR3D"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("NR3D_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无NR3D_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "NR3D_";
                    SumMainList.Add("//NR3D");
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("SNR"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("SNR_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无SNR_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "SNR_";
                    SumMainList.Add("//SNR");
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("YNR"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("YNR_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无YNR_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "YNR_";
                    SumMainList.Add("//YNR");
                    SumMainList.AddRange(mainList);
                }
                if (item.Description.Contains("CIP"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("CIP_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无CIP_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "CIP_";
                    SumMainList.Add("//CIP");
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("YDE"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("YDE_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无YDE_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "YDE_";
                    SumMainList.Add("//YDE");
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("CADJ"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("CADJ_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无CADJ_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "CADJ_";
                    SumMainList.Add("//CADJ");
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("IQ_Oneself"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("IQ_oneself_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无IQ_oneself_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        pcModel.Hdr_mode,
                        pcModel.Mjpeg_enable,
                        pcModel.Hsize_in,
                        pcModel.Vsize_in,
                        pcModel.Max_expo_line,
                        pcModel.Banding_mode,
                        pcModel.Flicker60HzUnit,
                        pcModel.Flicker50HzUnit,
                        pcModel.Long2short_delay,
                        pcModel.Short2vs_delay,
                        pcModel.Afc_enable
                    });

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "IQ_oneself_";
                    SumMainList.Add("//IQ_oneself");
                    SumMainList.AddRange(mainList);
                }
                if (item.Description.Contains("ISP_OSD"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("isp_osd_sde_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无isp_osd_sde_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        pcModel.Hdr_mode
                    });

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    PathName += "isp_osd_sde_";
                    SumMainList.Add("//isp_osd_sde");
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("IQ_switch"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("IQ_switch_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无IQ_switch_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        pcModel.Hdr_mode,
                        pcModel.Hsize_in,
                        pcModel.Vsize_in,
                        pcModel.Snr_blc_mode,
                        pcModel.Snr_blc_page_addr,
                        pcModel.Snr_blc_page_value,
                        pcModel.Snr_blc_addr,
                        pcModel.Snr_blc_channel_num,
                    });

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    SumMainList.Add("//IQ_switch");
                    PathName += "IQ_switch_";
                    List<string> mainList = (List<string>)value;
                    SumMainList.AddRange(mainList);
                }

                //if (item.Description.ToLower().Contains("car_back_line"))
                //{
                //    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                //    method.Invoke(objCreate, null);

                //    method = objCreate.GetType().GetMethod("car_back_line");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无car_back_line方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                //    object value = property.GetValue(objCreate, null);
                //    List<string> mainList = (List<string>)value;
                //    SumMainList.Add("//car_back_line");
                //    PathName += "car_back_line_";
                //    SumMainList.AddRange(mainList);

                //}

                if (item.Description.ToLower().Contains("Manual_3A_cfg"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("Manual_3A_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无Manual_3A_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        pcModel.Cofficient_self1,
                        pcModel.Sensor_hts_addr,
                        pcModel.Sensor_vts_addr,
                        pcModel.SENSOR_PCLK1
                    });

                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//Manual_3A_cfg");
                    PathName += "Manual_3A_cfg_";
                    SumMainList.AddRange(mainList);

                }
                //if (item.Description.Contains("Mjpeg"))
                //{

                //    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                //    method.Invoke(objCreate, null);

                //    method = objCreate.GetType().GetMethod("Mjpeg_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无Mjpeg_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                //    object value = property.GetValue(objCreate, null);
                //    List<string> mainList = (List<string>)value;
                //    SumMainList.Add("//Mjpeg");
                //    PathName += "Mjpeg_";
                //    SumMainList.AddRange(mainList);
                //}
                #region 废弃代码

                //if (item.Description.Contains("SNR/YNR/YDE"))
                //{
                //    ////SNR / YNR / YDE + --> SNR_cfg() + YNR_cfg() + YDE_cfg()

                //    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    method = objCreate.GetType().GetMethod("SNR_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无SNR_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);


                //    method = objCreate.GetType().GetMethod("YNR_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无YNR_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);


                //    method = objCreate.GetType().GetMethod("YDE_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无YDE_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);
                //    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                //    object value = property.GetValue(objCreate, null);
                //    List<string> mainList = (List<string>)value;
                //    SumMainList.Add("//SNR/YNR/YDE");
                //    PathName += "SNR_YNR_YDE_";
                //    SumMainList.AddRange(mainList);
                //    //处理代码
                //}


                //if (item.Description.Contains("AWB/CMX/CADJ"))
                //{
                //    //AWB/CMX/CADJ -->AWB_cfg() +CMX_cfg() +CADJ_cfg()

                //    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    method = objCreate.GetType().GetMethod("AWB_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无AWB_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, new object[] {
                //        pcModel.Hdr_mode
                //    });


                //    method = objCreate.GetType().GetMethod("CMX_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无CMX_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);


                //    method = objCreate.GetType().GetMethod("CADJ_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无CADJ_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);




                //    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                //    object value = property.GetValue(objCreate, null);
                //    List<string> mainList = (List<string>)value;
                //    SumMainList.Add("//AWB/CMX/CADJ");
                //    PathName += "AWB_CMX_CADJ_";
                //    SumMainList.AddRange(mainList);
                //    //处理代码

                //}

                //if (item.Description.Contains("Raw_gamma"))
                //{
                //    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    method = objCreate.GetType().GetMethod("Raw_gamma_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无Raw_gamma_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                //    object value = property.GetValue(objCreate, null);
                //    List<string> mainList = (List<string>)value;
                //    PathName += "Raw_gamma_";
                //    SumMainList.Add("//Raw_gamma");
                //    SumMainList.AddRange(mainList);
                //}

                //if (item.Description.Contains("Rgb_gamma"))
                //{
                //    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    method = objCreate.GetType().GetMethod("Rgb_gamma_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无Rgb_gamma_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                //    object value = property.GetValue(objCreate, null);
                //    List<string> mainList = (List<string>)value;
                //    PathName += "Rgb_gamma_";
                //    SumMainList.Add("//Rgb_gamma");
                //    SumMainList.AddRange(mainList);
                //}

                //if (item.Description.Contains("Yuv_gamma"))
                //{
                //    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无ClearMainList方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    method = objCreate.GetType().GetMethod("Yuv_gamma_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"CtoCodeLib 无Yuv_gamma_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);

                //    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                //    object value = property.GetValue(objCreate, null);
                //    List<string> mainList = (List<string>)value;
                //    PathName += "Yuv_gamma_";
                //    SumMainList.Add("//Yuv_gamma");
                //    SumMainList.AddRange(mainList);
                //}

                ////BLC_cfg() +CIP_cfg() +isp_osd_sde_cfg() +IQ_oneself_cfg()
                //if (item.Description.ToLower().Contains("other"))
                //{
                //    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                //    method.Invoke(objCreate, null);

                //    method = objCreate.GetType().GetMethod("BLC_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无BLC_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, new object[] {
                //        pcModel.Hdr_mode
                //    });
                //    method = objCreate.GetType().GetMethod("CIP_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无CIP_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, null);
                //    method = objCreate.GetType().GetMethod("isp_osd_sde_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无isp_osd_sde_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, new object[] {
                //        pcModel.Hdr_mode
                //    });
                //    method = objCreate.GetType().GetMethod("IQ_oneself_cfg");
                //    if (null == method)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show($"ClearMainList 无IQ_oneself_cfg方法！请联系管理员！");
                //        return;
                //    }
                //    method.Invoke(objCreate, new object[] {
                //        pcModel.Hdr_mode,
                //        pcModel.Mjpeg_enable,
                //        pcModel.Hsize_in,
                //        pcModel.Vsize_in,
                //        pcModel.Max_expo_line,
                //        pcModel.Long2short_delay,
                //        pcModel.Short2vs_delay,
                //        pcModel.Afc_enable
                //    });
                //    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                //    object value = property.GetValue(objCreate, null);
                //    List<string> mainList = (List<string>)value;
                //    PathName += "other_";
                //    SumMainList.Add("//other");
                //    SumMainList.AddRange(mainList);

                //}
                #endregion


            }
            MethodInfo method2 = objCreate.GetType().GetMethod("ClearMainList");
            method2.Invoke(objCreate, null);
            MethodInfo method1 = objCreate.GetType().GetMethod("Top_enable_cfg");
            if (null == method1)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show($"无Top_enable_cfg方法！请联系管理员！");
                return;
            }
            method1.Invoke(objCreate, new object[] {
                        pcModel.Hdr_mode,
                        pcModel.Isp_scale_sel,
                        pcModel.Nr3d_enable,
                        pcModel.Afc_enable,
                    });
            PropertyInfo propertya = objCreate.GetType().GetProperty("MainList");
            object values = propertya.GetValue(objCreate, null);
            List<string> mainLists = (List<string>)values;
            SumMainList.Add("//Top_enable");
            PathName += "Top_enable";
            SumMainList.AddRange(mainLists);
            SaveFileDialog sfd = new SaveFileDialog();
            //设置文件类型 
            sfd.Filter = "导出文件（*.txt）|*.txt";
            //设置默认文件类型显示顺序 
            sfd.FilterIndex = 1;
            //保存对话框是否记忆上次打开的目录 
            sfd.RestoreDirectory = true;
            sfd.FileName = "IQ_setting_" + DateTime.Now.ToString("yyyyMMddHHmmss");
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                
                var listPath = ListConversionIq(SumMainList);
                File.WriteAllLines($"{sfd.FileName}", listPath);
                DevExpress.XtraEditors.XtraMessageBox.Show($"导出成功！ 文件路径：{sfd.FileName}");
            }
        }
        private string GetConfigValue(string strKey)
        {
            var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var settings = configFile.AppSettings.Settings;

            return settings[strKey].Value;
        }
        public List<string> ListConversionIq(List<string> mainList)
        {
            int result;
            mainList = mainList.Select(item => item == "\n" ? "" : item).ToList();
            if (GetConfigValue("IsSerial") != "TVE")
            {
                var aaa = mainList.IndexOf("//TVE_stream_on\n");
                if (mainList.Any(c=>c == "//TVE_stream_on\n"))
                {
                    for (int i = 0; i < 4; i++)
                    {
                        mainList.RemoveAt(aaa);
                    }
                }
               
            }
            for (int i = 0; i < mainList.Count(); i++)
            {
                if (mainList[i] == ("//tve_stream_on"))
                {
                    
                }
                var Spmainlist =  mainList[i].Replace(" ","").Split(',');
                if (Spmainlist.Count() > 1 && int.TryParse(Spmainlist[0].Replace("0x",""), System.Globalization.NumberStyles.HexNumber, null, out result))
                {
                    
                    var log = SerialSend.ReadRegister(Convert.ToUInt32(Spmainlist[0],16), sPortTemp);
                    if (mainList[i].Contains("don't_modify"))
                    {
                        log = Convert.ToUInt32(Spmainlist[1],16);
                    }
                    Spmainlist[1] ="0x" + log.ToString("X2");
                }
                mainList[i] = string.Join(",", Spmainlist);
            }
           return listConversionAdd(mainList);
        }

        public List<string> listConversionAdd(List<string> mainList)
        {
            int result;
            string fffdstr = "0x";
            string fffestr = "0x";
            bool isfffde = false;
            for (int i = 0; i < mainList.Count(); i++)
            {
                if (mainList[i].Contains("//enable"))
                {

                }
                var Spmainlist = mainList[i].Replace(" ", "").Split(',');
                if (Spmainlist.Count() > 1 && int.TryParse(Spmainlist[0].Replace("0x", ""), System.Globalization.NumberStyles.HexNumber, null, out result))
                {
                    Spmainlist[0] = Spmainlist[0].Replace("0x", "");
                    if (!Spmainlist[0].Substring(0, 4).Contains(fffdstr + fffestr))
                    {
                        fffdstr = Spmainlist[0].Substring(0, 2);
                        fffestr = Spmainlist[0].Substring(2, 2);
                        isfffde = true;
                    }
                    Spmainlist[0] ="0x"+ Spmainlist[0].Substring(4, 4);
                }
                if (isfffde)
                {
                    mainList.Insert(i, $"0xfffd,0x{fffdstr},");
                    mainList.Insert(i+1, $"0xfffe,0x{fffestr},");
                    mainList[i+2] = string.Join(",", Spmainlist);
                    i += 2;
                    isfffde = false;
                }
                else
                {
                    mainList[i] = string.Join(",", Spmainlist).ToLower();
                }
               
            }

            return mainList;

        }

        private void check_IspOSD_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < parChecked.Items.Count(); i++)
            {
                parChecked.SetItemChecked(i, check_IspOSD.Checked);
            }
        }

        private void checkEdit1_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < checkedListBoxControl1.Items.Count(); i++)
            {
                checkedListBoxControl1.SetItemChecked(i, checkEdit1.Checked);
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            //00-AE_LFC          01-SCBL           02-DCBL          03-Register_Mirror_Flip          04-GPIO_SCBL          05-GPIO_Mirror_Flip          06-DAC_MakeUp          07-PWM
            //08-ADC             09-ADC_OSD        10-IR_Cut        11-Watch_Dog                     12-PSRAM_Check        13-AutoSync                  14-SysTick_Cfg         15-TVE_Stream_On
            //xchip_tool中的IQ参数导出，无需导出11~15
            List<string> SumMainList = new List<string>();
            string PathName = "";
            var chkIndexCollection = this.checkedListBoxControl1.CheckedItems.Cast<CheckedListBoxItem>()
    .OrderBy(item => item.Value);//获得所有选中行的集合
            var path = Application.StartupPath + "\\" + "FunctionCodeLib.dll";
            if (!File.Exists(path))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show($"未找到到相应的FunctionCodeLib.DLL！请联系管理员！");
                return;
            }
            FunctionConfig fcModel = new FunctionConfig();
            fcModel.Initialization(sPortTemp);
            Assembly assembly = Assembly.LoadFile(path);
            var objCreate = assembly.CreateInstance("XChipTool.FunctionCode");
            foreach (CheckedListBoxItem item in chkIndexCollection)
            {
                if (item.Description==("SCBL"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("SCBL_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无SCBL方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.SCBL_size1,
                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//SCBL");
                    PathName += "SCBL_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("AE_LFC"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("AE_LFC_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无AE_LFC_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.Ae_lfc_enable,
                        fcModel.Snr_vts_addr_enable,
                        fcModel.Snr_vts_addr,
                        fcModel.Vts_in,
                        fcModel.Add_exp_line,
                        fcModel.Insert_frame_num_max,
                        fcModel.VTS_write_order1,
                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//AE_LFC");
                    PathName += "AE_LFC_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("PWM"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("PWM_Cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无PWM_Cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.PWM_En1,
                        fcModel.PWM_Pin_Sel1,
                        
                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//PWM");
                    PathName += "PWM_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("Watch_Dog"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("Watch_Dog_Cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无Watch_Dog_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.Watch_Dog_En1,
                        fcModel.Watch_Dog_Time1,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//Watch_Dog");
                    PathName += "Watch_Dog_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("PSRAM_Check"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("PSRAM_Check_Cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无PSRAM_Check_Cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.PSRAM_EN1,
                        fcModel.PSRAM0_EN1,
                        fcModel.PSRAM1_EN1,
                        fcModel.Psram0_MR0_Value1,
                        fcModel.Psram1_MR0_Value1,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//PSRAM_Check");
                    PathName += "PSRAM_Check_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("DCBL"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("DCBL_Cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无DCBL_Cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.NDcbl_Section_Index,
                        fcModel.NDcbl_Load_Image_Flag,
                        fcModel.Display_Image_Enable1,
                        fcModel.NDcbl_Cur_Image_Index,
                        fcModel.NDcbl_Auto_Display,
                        fcModel.NDcbl_Auto_Dispaly_Frame_Num,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//DCBL");
                    PathName += "DCBL_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("AutoSync"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("AutoSync_Cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无AutoSync_Cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.Auto_sync_en,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//AutoSync");
                    PathName += "AutoSyncL_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("IR_Cut"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("IR_Cut_Cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无IR_Cut_Cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.Ir_off_time,
                        fcModel.Ir_on_time,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//IR_Cut");
                    PathName += "IR_Cut_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("GPIO_SCBL"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("GPIO_SCBL_Cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无GPIO_SCBL_Cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.CarBackLine_Mode1,
                        fcModel.CarBackLine_Level_Toggle1,
                        fcModel.CarBackLine_Pin_Sel1,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//GPIO_SCBL");
                    PathName += "GPIO_SCBL_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("Register_Mirror_Flip"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("Register_Mirror_Flip_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无Register_Mirror_Flip_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.Sensor_Mirror_Flip_Addr_Enable1,
                        fcModel.Sensor_Mirror_Flip_Addr1,
                        fcModel.Mirror_Off_Flip_Off_Value1,
                        fcModel.Mirror_On_Flip_Off_Value1,
                        fcModel.Mirror_Off_Flip_On_Value1,
                        fcModel.Mirror_On_Flip_On_Value1,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//Register_Mirror_Flip");
                    PathName += "Register_Mirror_Flip_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("GPIO_Mirror_Flip"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("GPIO_Mirror_Flip_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无GPIO_Mirror_Flip_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.Mirror_Pin_Sel1,
                        fcModel.Flip_Pin_Sel1,
                        fcModel.Mirror_Level_Toggle1,
                        fcModel.Flip_Level_Toggle1,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//GPIO_Mirror_Flip");
                    PathName += "GPIO_Mirror_Flip_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("DAC_MakeUp"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("DAC_MakeUp_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无DAC_MakeUp_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.DAC_Make_Up_Enable1,
                        fcModel.DAC_Make_Up_Pin_Select1,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//DAC_MakeUp");
                    PathName += "DAC_MakeUp_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description == ("ADC"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("ADC_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ADC_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.Adc_chg_mask,

                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//ADC");
                    PathName += "ADC_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("ADC_OSD"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("ADC_OSD_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ADC_OSD_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.Adc_up_value,
                        fcModel.Adc_down_value,
                        fcModel.Adc_right_value,
                        fcModel.Adc_left_value,
                        fcModel.Adc_menu_value,
                        fcModel.Adc_range_value,
                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//ADC_OSD");
                    PathName += "ADC_OSD_";
                    SumMainList.AddRange(mainList);
                }

                if (item.Description.Contains("TVE_Stream_On"))
                {
                    MethodInfo method = objCreate.GetType().GetMethod("ClearMainList");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无ClearMainList方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, null);

                    method = objCreate.GetType().GetMethod("TVE_Stream_On_cfg");
                    if (null == method)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show($"FunctionCodeLib 无TVE_Stream_On_cfg方法！请联系管理员！");
                        return;
                    }
                    method.Invoke(objCreate, new object[] {
                        fcModel.Global_Stream_On_Enable1,
                        fcModel.Stream_On_Delay_Enable1,
                        fcModel.Stream_On_Delay_Cnt1,
                    });
                    PropertyInfo property = objCreate.GetType().GetProperty("MainList");
                    object value = property.GetValue(objCreate, null);
                    List<string> mainList = (List<string>)value;
                    SumMainList.Add("//TVE_Stream_On");
                    PathName += "TVE_Stream_On_";
                    SumMainList.AddRange(mainList);
                }

            }
            //MethodInfo method2 = objCreate.GetType().GetMethod("ClearMainList");
            //method2.Invoke(objCreate, null);
            //MethodInfo method1 = objCreate.GetType().GetMethod("SysTick_Cfg");
            //if (null == method1)
            //{
            //    DevExpress.XtraEditors.XtraMessageBox.Show($"无SysTick_Cfg方法！请联系管理员！");
            //    return;
            //}
            //method1.Invoke(objCreate, new object[] {
            //            fcModel.System_Tick_Enable1,
            //            fcModel.NSysTickClock,
            //        });
            //PropertyInfo propertya = objCreate.GetType().GetProperty("MainList");
            //object values = propertya.GetValue(objCreate, null);
            //List<string> mainLists = (List<string>)values;
            //SumMainList.Add("//SysTick");
            //PathName += "SysTick";
            //SumMainList.AddRange(mainLists);
            SaveFileDialog sfd = new SaveFileDialog();
            //设置文件类型 
            sfd.Filter = "导出文件（*.txt）|*.txt";
            //设置默认文件类型显示顺序 
            sfd.FilterIndex = 1;
            //保存对话框是否记忆上次打开的目录 
            sfd.RestoreDirectory = true;
            sfd.FileName = "Function_Setting" + DateTime.Now.ToString("yyyyMMddHHmmss");
            if (sfd.ShowDialog() == DialogResult.OK)
            {

                var listPath = ListConversionIq(SumMainList);
                File.WriteAllLines($"{sfd.FileName}", listPath);
                DevExpress.XtraEditors.XtraMessageBox.Show($"导出成功！ 文件路径：{sfd.FileName}");
            }
        }
    }
}